package com.pengcheng.taskapplication.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.pengcheng.taskapplication.R;
import com.pengcheng.taskapplication.model.CarSignModel;

import java.util.List;

public class CarSignAdapter extends BaseAdapter {

	Context context;
	LayoutInflater inflater;
	List<CarSignModel> carModels;
	int last_item;
	private int selectedPosition = -1;
	public CarSignAdapter(Context context, List<CarSignModel> carModels){
		this.context = context;
		this.carModels = carModels;
		inflater= LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return carModels.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return carModels.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@SuppressLint("ResourceAsColor")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder  holder = null;
		if(convertView==null){
			convertView = inflater.inflate(R.layout.activity_car_list_item_sign, null);
			holder = new ViewHolder();
			holder.car_num =(TextView)convertView.findViewById(R.id.car_num);
			holder.car_e_num=(TextView)convertView.findViewById(R.id.car_e_num);
			holder.tv_sign_tip=(TextView)convertView.findViewById(R.id.tv_sign_tip);
			holder.ll_sign=(LinearLayout)convertView.findViewById(R.id.ll_sign);
			convertView.setTag(holder);
		}
		else{
			holder=(ViewHolder)convertView.getTag();
		}

		CarSignModel model= carModels.get(position);
		holder.car_num.setText(model.getPlate_no());
		holder.car_e_num.setText(model.getEcard_code());

		if(model.isSign.equals("2")){
			holder.tv_sign_tip.setTextColor(context.getResources().getColor(R.color.white));
			holder.ll_sign.setBackgroundResource(R.drawable.bg_car_show_sign);
			holder.tv_sign_tip.setText("未签约");

		}else {
			holder.tv_sign_tip.setTextColor(context.getResources().getColor(R.color.un_sign_color));
			holder.ll_sign.setBackgroundResource(R.drawable.bg_car_show_unsign);
			holder.tv_sign_tip.setText("已签约");

		}

		return convertView;
	}

	public static class ViewHolder{
		public TextView car_num;
		public TextView car_e_num;
		public TextView tv_sign_tip;
		public LinearLayout ll_sign;

	}

	public void setSelectedPosition(int position) {
		selectedPosition = position;
	}

}
